package com.inhim.pjhim.adapter.provider;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chaychan.adapter.BaseItemProvider;
import com.inhim.pjhim.R;
import com.inhim.pjhim.activity.TypeListActivity;
import com.inhim.pjhim.adapter.TagReaderListAdapter;
import com.inhim.pjhim.entity.TagReaderList;
import com.inhim.pjhim.utils.ImageLoaderUtils;
import com.inhim.pjhim.view.CustomRoundAngleImageView;

/**
 * @author ChayChan
 * @description: 头部banner
 * @date 2018/3/22  14:48
 * 未使用
 */

public class ReaderItemProvider extends BaseItemProvider<TagReaderList.ReaderType, BaseViewHolder> {

    private Context context;
    public ReaderItemProvider(Context context) {
        this.context=context;
    }

    @Override
    public void convert(BaseViewHolder helper, final TagReaderList.ReaderType news, int i) {
        if (news == null) {
            //如果没有标题，则直接跳过
            return;
        }
        try{
            CustomRoundAngleImageView circleImageView = helper.getView(R.id.circleImageView);
            TextView textview = helper.getView(R.id.textview);
            ImageLoaderUtils.setImage(news.getIcon(),circleImageView);
            textview.setText(news.getName());
            ConstraintLayout item_lin=helper.getView(R.id.item_lin);
            item_lin.setOnClickListener(v -> {
                Intent intent=new Intent(context, TypeListActivity.class);
                intent.putExtra("TAG","ReaderItemProvider");
                if(news.getType()==1){
                    intent.putExtra("Title","阅读");
                }else if(news.getType()==2){
                    intent.putExtra("Title","视频");
                }else if(news.getType()==3){
                    intent.putExtra("Title","聆听");
                }
                intent.putExtra("ReaderTypeId",news.getReaderTypeId());
                intent.putExtra("Type",String.valueOf(news.getType()));
                context.startActivity(intent);
            });
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    public int viewType() {
        return TagReaderListAdapter.READER_TYPE;
    }

    @Override
    public int layout() {
        return R.layout.provider_reader;
    }

}
